package com.android.lovely.ui.adapter

import android.view.ViewGroup
import androidx.core.graphics.toColorInt
import androidx.recyclerview.widget.DiffUtil
import androidx.recyclerview.widget.RecyclerView
import com.android.lovely.R
import com.android.lovely.data.HomeListData
import com.android.lovely.data.TradeType
import com.android.lovely.data.TransactionListBean
import com.android.lovely.databinding.ItemListBinding
import com.android.lovely.databinding.ItemTransBinding
import com.android.lovely.framework.BaseLoadAdapter
import com.kotlin.extensions.inflater.LayoutInflaterExt.layoutInflater

/**
 *
 * @author why
 * @date 2025/3/13 17:09
 */
class TansAdapter: BaseLoadAdapter<TransactionListBean, TansAdapter.TansListHolder>(
    object :
        DiffUtil.ItemCallback<TransactionListBean>() {
        override fun areItemsTheSame(oldItem: TransactionListBean, newItem: TransactionListBean): Boolean {
            return oldItem.id == newItem.id
        }

        override fun areContentsTheSame(oldItem: TransactionListBean, newItem: TransactionListBean): Boolean {
            return oldItem == newItem
        }

    }
) {

    override fun onBindViewHolder(p0: TansListHolder, p1: Int) {
        val item = getItem(p1) ?: return
        val type = TradeType.getTypeById(item.type)
        p0.binding.apply {
            payName.text = item.msg
            payName.setText(type.contentResId)
            payTime.text = item.cTime
            tvDiamond.text = item.getDisplayText()
            tvDiamond.setTextColor(
               item.getTextColor()
            )
        }
    }

    override fun onCreateViewHolder(p0: ViewGroup, p1: Int): TansListHolder {
        return TansListHolder(p0)
    }

    class TansListHolder(
        parent: ViewGroup,
        val binding: ItemTransBinding = ItemTransBinding.inflate(
            parent.layoutInflater,
            parent,
            false
        )
    ) : RecyclerView.ViewHolder(binding.root)

}